<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<script th:src="@{/layui/layui.all.js}"></script>
<link rel="stylesheet" th:href="@{/layui/css/layui.css}">
<body>
<button class="layui-btn"  onclick="genAll()">批量生成代码</button>
<table id="demo" lay-filter="test"></table>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="gen">生成代码</a>
</script>
<script>
    var  table;
    layui.use('table', function(){
         table = layui.table;
        //第一个实例
        table.render({
            elem: '#demo',
            url: '/tool/gen/list' //数据接口
            ,cols: [
                [
                    {type: 'checkbox', fixed: 'left'},
                    {field: 'tableName', title: '表名称', width:'20%'}
                    ,{field: 'tableComment', title: '表描述',width:'20%',}
                    ,{field: 'createTime', title: '创建时间', width:'20%',}
                    ,{field: 'updateTime', title: '更新时间', width:'20%',}
                    ,{ title: '操作', width:'20%',align: 'center',toolbar: '#barDemo'}
                ]
            ]
        });
        table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
            var tableName=data.tableName;
            layEvent = obj.event; //获得 lay-event 对应的值
            if(layEvent === 'gen'){
                layer.confirm('确认要生成代码么', function(index){
                    layer.close(index);
                    //向服务端发送删除指令
                    location.href = "/tool/gen/genCode/" + tableName;
                });
            }
        });

    });
    function genAll() {
        var checkStatus = table.checkStatus('demo');
        console.log(checkStatus);
        var tables='';
        if(checkStatus.data.length>0){
            for (var i = 0; i <checkStatus.data.length ; i++) {
                tables=checkStatus.data[i].tableName+","+tables;
            }
            layer.confirm('确认要生成代码么', function(index){
                layer.close(index);
                //向服务端发送删除指令
                location.href = "/tool/gen/batchGenCode?tables=" + tables;
            });
        }

       /* var rows = table.selectColumns("tableName");
        if (rows.length == 0) {
            $.modal.alertWarning("请选择要生成的数据");
            return;
        }
        $.modal.confirm("确认要生成选中的" + rows.length + "条数据吗?", function() {
            location.href = prefix + "/batchGenCode?tables=" + rows;
            layer.msg('执行成功,正在生成代码请稍后…', { icon: 1 });
        });*/
    }

</script>
</body>
</html>